package de.akabahn.ebd.comm.dbd;

/**
 * Supported DBD commands:<br>
 * <ul>
 * <li>End of session <code>(0x02)</code></li>
 * <li>Subscribe Database <code>(0x04)</code></li>
 * <li>Query Database <code>(0x05)</code></li>
 * <li>Set Value <code>(0x06)</code></li>
 * <li>Force Variable <code>(0x0a)</code></li>
 * <li>Unforce Variable <code>(0x0b)</code></li>
 * </ul>
 * 
 * @author Peter Eimann
 * @since 0.2
 * @version 0.2
 */
public enum DBDCommand {
	NONE(0x00), ENDOFSESSION(0x02), SUBSCRIBE(0x04), QUERY(0x05), SET(0x06), FORCE(0x0a), UNFORCE(0x0b);

	private int value;

	DBDCommand(int value) {
		this.value = value;
	}

	public byte getValue() {
		return (byte) value;
	}

	public static DBDCommand fromValue(byte value) {
		switch (value) {
		case 0x00:
			return NONE;
		case 0x02:
			return ENDOFSESSION;
		case 0x04:
			return SUBSCRIBE;
		case 0x05:
			return QUERY;
		case 0x06:
			return SET;
		case 0x0a:
			return FORCE;
		case 0x0b:
			return UNFORCE;
		default:
			return null;
		}
	}
}
